#ifndef H_SPRITE
#define H_SPRITE

#include "debug.h"
#include "rect.h"
#include <string>

#define P_LOAD_FUNCTION( varName ) int (*varName)( std::string&, void**)

class Sprite {
   private:
      std::string filename;
      void* surface;
      Rect* geometry;
      P_LOAD_FUNCTION(loadFP);
   public:
      bool animated;

      Sprite () {
	 animated = false;
      }
      Sprite ( std::string &, P_LOAD_FUNCTION(_loadFP), UINT, UINT );

      int load () {	//#D
	 return loadFP(filename, &surface);
	 //Loads the file into memory
      }

      std::string getFileName () const {	  //#D
	 return filename; }

      void* getSurface() const {       //#D
	 return surface;
      }

      void setSurface ( void* _a) {	  //#D
	 surface = _a; 
      }

      Rect* getGeometry( ) const {    //#D
	 return geometry;
      }

      void setGeometry( Rect* _geo ) {
	 geometry = _geo;
      }

      virtual Rect* getFrame ( UINT i ) {	//#D
	 return NULL; 
      }
};

class AnimatedSprite: public Sprite {
   private:
      UINT frames;
   public:
      AnimatedSprite ( std::string _filename, P_LOAD_FUNCTION(_loadFP) ,UINT _frames, UINT _width, UINT _height ) : Sprite ( _filename, _loadFP, _width, _height ) {
	 frames = _frames;

	 Rect* r = new Rect [ frames ];
	 setGeometry ( r );	 
	 generateRects( _width, _height);
	 animated = true;
      }

      virtual Rect* getFrame (UINT i ) const {      //#D
	 return getGeometry()+i; 
      }

      void generateRects( UINT, UINT);
      
      UINT getFrames() const {	    //#D
	 return frames;
      }
};



#endif
